package com.google.project.shared;

//import java.nio.charset.Charset;
import java.security.MessageDigest;

//import javax.crypto.Cipher;
//import javax.crypto.SecretKey;
//import javax.crypto.SecretKeyFactory;
//import javax.crypto.spec.DESKeySpec;
//
//import org.apache.commons.codec.binary.Base64;

public class CryptString {
//	private Cipher encryptCipher=null ;
//	private Cipher decryptCipher=null ;
//	
//	public CryptString(){}
//	// public SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
//	/**
//	 * Construct a new object which can be utilized to encrypt and decrypt
//	 * strings using the specified key with a DES encryption algorithm.
//	 * 
//	 * @param key
//	 *            The secret key used in the crypto operations.
//	 * @throws Exception
//	 *             If an error occurs.
//	 * 
//	 */
//	public CryptString(SecretKey key){
//		try{
//		encryptCipher = Cipher.getInstance("DES");
//		decryptCipher = Cipher.getInstance("DES");
//		encryptCipher.init(Cipher.ENCRYPT_MODE, key);
//		decryptCipher.init(Cipher.DECRYPT_MODE, key);
//		}catch(Exception e){}
//	}
//
//	/**
//	 * Encrypt a string using DES encryption, and return the encrypted string as
//	 * a base64 encoded string.
//	 * 
//	 * @param unencryptedString
//	 *            The string to encrypt.
//	 * @return String The DES encrypted and base 64 encoded string.
//	 * @throws Exception
//	 *             If an error occurs.
//	 */
//	private static Charset  UTF8 = Charset.forName("UTF-8");
//	public String encryptBase64(String unencryptedString) throws Exception {
//		
//		// Encode the string into bytes using utf-8
//		byte[] unencryptedByteArray = unencryptedString.getBytes(UTF8);
//
//		// Encrypt
//		byte[] encryptedBytes = encryptCipher.doFinal(unencryptedByteArray);
//
//		// Encode bytes to base64 to get a string
//		byte[] encodedBytes = Base64.encodeBase64(encryptedBytes);
//
//		return new String(encodedBytes);
//	}
//
//	/**
//	 * Decrypt a base64 encoded, DES encrypted string and return the unencrypted
//	 * string.
//	 * 
//	 * @param encryptedString
//	 *            The base64 encoded string to decrypt.
//	 * @return String The decrypted string.
//	 * @throws Exception
//	 *             If an error occurs.
//	 */
//	public String decryptBase64(String encryptedString) throws Exception {
//		// Encode bytes to base64 to get a string
//		byte[] decodedBytes = Base64.decodeBase64(encryptedString.getBytes());
//
//		// Decrypt
//		byte[] unencryptedByteArray = decryptCipher.doFinal(decodedBytes);
//
//		// Decode using utf-8
//		return new String(unencryptedByteArray, "UTF8");
//	}
//
//	public static  SecretKey getKey() {
//		DESKeySpec key = null;
//		SecretKeyFactory keyFactory = null;
//		try {
//			String password = "secretpassword";
//			key = new DESKeySpec(password.getBytes());
//			keyFactory = SecretKeyFactory.getInstance("DES");
//			return keyFactory.generateSecret(key);
//		} catch (Exception e) {
//			e.getMessage();
//		}
//		return null;
//	}
	 public String encryptPassword(String ep){
	        String result="";
	        try{
	            MessageDigest md=MessageDigest.getInstance("MD5");
	            md.update(ep.getBytes("UTF8"));
	            byte[]s=md.digest();
	            for(int i=0;i<s.length;i++){
	                result+=Integer.toHexString((0x000000ff &s[i])| 0xffffff00).substring(6);
	            }
	        }catch(Exception e){
	            System.out.println("e");
	        }
	        return result;
	    }
}
